[The following is excerpted from the article "CGI and AppleScript," Dr. Dobb's Sourcebook, Nov./Dec. 1995.]
On the Macintosh, CGI applications can be written using AppleScript, the built-in scripting language of the Macintosh operating system. AppleScript was designed as a high-level, dynamic language to provide a systemwide scripting mechanism, always available, which can reach out to existing applications.
By far, AppleScript’s most powerful capability is being able to communicate with and control other applications, including well over 100 off-the-shelf scriptable applications. This allows you to quickly put together scenarios, simple or complex. Within an AppleScript CGI, you can process data or instructions entered into a form. You can initiate a database search, assembly of text, produce charts or graphics, all driven from user choices. In addition, there’s sending e-mail, assembling new HTML for use in creating subsequent Web pages, and dealing with runtime errors.
AppleScript works its magic through application-specific vocabularies, which are housed within scriptable applications. A vocabulary extends the language to include new terms representing actions and objects specific to the particular application. Together with AppleScript’s built-in terms, you write scripts by putting together sentences, often grammatically correct.
A sample AppleScript CGI
Suppose you maintain a regularly-updated database of information in a database that includes a table of numeric values, and you want to provide, on demand to your Web users, the table in the form of a chart. This example uses three familiar applications: FileMaker Pro (to hold the data), DeltaGraph Pro (to make a chart of the data), and Clip2Gif (to store the chart in a GIF file). You can use redirection (“Location” in the reply header) to point to the Web server to the GIF file. The following is intended as inspiration, not as a working sample.
property crlf : (ASCII character 13) & (ASCII character 10)